<template>
    <div>
        <el-container class="form-container">
            <el-card class="box-card" shadow="never">
                <div slot="header" class="clearfix">
                    <span>Demo</span>
                    <el-button type="primary" size="mini" style="float:right;padding: 6px 9px;" @click="submitForm">保存</el-button>
                </div>
                <div >
                   <el-form  :rules="rules"  ref="form"   :model="form" size="small" label-width="120px">
                        <el-row>
                          <el-col :span="12">
                              <el-form-item  label="分类名称"  prop="fdName">
                                  <el-input class="input" v-model="form.fdName" ></el-input>
                              </el-form-item>
                          </el-col>
                          <el-col :span="12">
                              <el-form-item  label="所属分类"  prop="fdParentName">
                                <SelectTree
                                    :props="props"
                                    :action="url"
                                    v-model="form.fdParentName"
                                    :id.sync="form.fdParentId"
                                    clearable
                                    />
                              </el-form-item>
                          </el-col>
                        </el-row>
                        <el-row>
                          <el-col :span="12">
                              <el-form-item  label="排序号"  prop="fdOrder">
                                  <el-input-number v-model="form.fdOrder" :min="0" ></el-input-number>
                              </el-form-item>
                          </el-col>
                        </el-row>
                   </el-form>
                </div>
            </el-card>
        </el-container>
    </div>
</template>
<script>
import SelectTree from "@/components/common/form/FancySelectTree";
import dateUtils from '@/utils/dateUtils';
import formUtils from '@/utils/formUtils';
export default {
    name: "SysPermissionRoleCategoryAdd",
    components: {
        SelectTree
    },
    data() {
        return {
          form: {
              fdParentId:'',
              fdOrder:'',
              fdParentName:'',
              fdName:'',
              fdId:'',
              fdCreateTime:''
          },
          rules:{
            fdName :[{required: true, message: '请输入分类名称', trigger: 'blur'}]
          },
          props: {
            label: "name",
            value: "id",
          },
          url:"/sys/permission/sys_permission_role_category/treeData"
        }
    },
    created() {
        this.initParam();
    },
    methods: {
        submitForm() {
            this.$refs['form'].validate((valid) => {
                if (valid) {
                    this.fullscreenLoading = true;
                    let forms = formUtils.convertToModel(this.form);
                    this.$put('/api/sys/permission/sys_permission_role_category',forms).then((res) => {
                        this.fullscreenLoading = false;
                        if(res.status==1){
                            this.$message({
                                message: res.message,
                                type: 'success',
                                onClose:()=>{
                                    this.$common.closeTag();
                                }
                            });
                        }else{
                            this.$message.error(res.message);
                        }
                    });

                }
            });
        },
        initParam() {
            let fdId = this.$route.query.id;
            if(formUtils.isNotEmpty(fdId)){
                this.fullscreenLoading = true;
                this.$fetch('/api/sys/permission/sys_permission_role_category',{
                    id:fdId
                }).then((res) => {
                    formUtils.convertToForm(res.data,this.form);
                    this.fullscreenLoading = false;
                });
            };
            let fdParentId = this.$route.query.fdParentId;
            if(formUtils.isNotEmpty(fdParentId)){
                this.$fetch('/api/sys/permission/sys_permission_role_category',{
                    id:fdParentId
                }).then((res) => {
                  this.form.fdParentId = res.data.fdId;
                  this.form.fdParentName = res.data.fdName;
                });
            };
        },
        handleChange(val) {
        }
    }
}
</script>
<style scoped >
@import "~@/assets/css/form.css";
</style>